<?php

namespace app\common\model;

use think\Model;

class CourseModel extends Model
{
    protected $table = 'edu_course';

    public function coursecate(){
        return $this->belongsTo('CourseCateModel','cate_id');
    }

    public function school(){
        return $this->belongsTo('SchoolModel','school_id');
    }

    public function schoolgrade(){
        return $this->belongsTo('SchoolGradeModel','grade_id');
    }

    public function schoolclass(){
        return $this->belongsTo('SchoolClassModel','class_id');
    }

    public function teacher(){
        return $this->belongsTo('UserModel','teacher_id');
    }

    /**
     * 报名人数
     */
    public function getSignTotalsAttr($val, $row){
        return UserTimesModel::where('course_id',$row['id'])->count();//已报名人数
    }
}